package com.example.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.result.MyPage;
import com.example.demo.result.Result;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import com.example.demo.service.IArticleImgService;
import com.example.demo.entity.ArticleImg;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 文章图片表 前端控制器
 * </p>
 *
 * @author Mr.Yang
 * @since 2024-06-03
 */
@Api(tags = "文章图片接口")
@RestController
@RequestMapping("/article-img")
public class ArticleImgController {

    @Resource
    private IArticleImgService articleImgService;

    /**
     * 查询所有接口
     * @return
     */
    @ApiOperationSupport(author = "Mr.Yang")
    @ApiOperation(value = "查询文章图片表所有数据")
    @GetMapping
    public Result<List<ArticleImg>> findAll() {
        return Result.success(articleImgService.selectAllImg()).msg("查询成功");
    }

    /**
     * 根据id查询数据接口
     * @param id
     * @return
     */
    @ApiOperationSupport(author = "Mr.Yang")
    @ApiOperation(value = "根据id查询数据接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "组件id",required = true)
    })
    @GetMapping("/{id}")
    public Result<ArticleImg> findOne(@PathVariable  Integer id) {
        // 尝试根据文章ID查找图片信息
        List<ArticleImg> articleImg = articleImgService.selectByArticleId(id);
        // 判断查询结果是否为空
        if (articleImg.size() ==0) {
            // 如果没有找到对应图片，返回失败结果
            return Result.error().msg("未找到对应的文章图片");
        }
        return Result.success(articleImg).msg("查询成功");

    }
}